package DomainLayer;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import Annotations.AttributeNameAnnotation;
import Annotations.EntityNameAnnotation;

@EntityNameAnnotation(Name = "Movie")
public class MovieEntity extends BaseMovieEntity {

    @AttributeNameAnnotation(Name = "Comments", isAggregator = true, linksTable = "MovCom_Link_Table", sourceTableName = "Commentary", genericParam = "Commentary")
    protected ArrayList<CommentaryEntity> comments;

    public MovieEntity(String movieDescription, double ratingIMDB,
			MPAARatingStatus ratingMPAA, int rating, String name,
			HashSet<String> genre, String cover, ProfitValueObject profit,
			ArrayList<String> actors) {
		super(movieDescription, ratingIMDB, ratingMPAA, rating, name, genre,
				cover, profit, actors);
	}

	public MovieEntity() {
	}

    @Override
    public CommentaryEntity createCommentary(String comment, UserEntity user) {
        CommentaryEntity commentary = new CommentaryEntity(user, null, comment);
        comments.add(commentary);
        return commentary;
    }

    @Override
    public void removeCommentary(int id) {
        for (Iterator<CommentaryEntity> it = comments.iterator(); it.hasNext();) {
            if (it.next().getId().equals(id)) {
                it.remove();
                break;
            }
        }
    }

    @Override
    public List<CommentaryEntity> getCommentaries() {
        return comments;
    }
}
